package com.ktg.web.mainData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.mainData.MdItem;
import com.ktg.ktgcommon.domain.mainData.MdUnitMeasure;
import com.ktg.ktgcommon.result.R;
import com.ktg.service.UnitMeasureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UnitMeasureController {


    @Autowired
    private UnitMeasureService unitMeasureService;

    //根据条件查询数据，没有条件查询全部
    @PostMapping("/unit/checkListUnit")
    public R checkListUnit(String measureCode ,String measureName,
                           @RequestParam(defaultValue = "1") Integer pageNo,
                           @RequestParam(defaultValue = "5") Integer pageSize){
        Page<MdUnitMeasure> page = new Page<>(pageNo, pageSize);
        Page<MdUnitMeasure> mdUnitMeasurePage = unitMeasureService.checkListUnitPage(page, measureCode, measureName);
        return R.OK(mdUnitMeasurePage);
    }

    //根据id查询单条数据
    @PostMapping("/unit/CheckUnitById/{measureId}")
    public R CheckUnitById(@PathVariable("measureId")Integer measureId){
        MdUnitMeasure mdUnitMeasure = unitMeasureService.CheckUnitById(measureId);
        return R.OK(mdUnitMeasure);
    }
    //根据传递进来的值进行添加或修改的操作
    @PostMapping("/unit/AddOrChUnit")
    public R AddOrChUnit(MdUnitMeasure mdUnitMeasure){
        Integer integer = unitMeasureService.AddOrChUnit(mdUnitMeasure);
        return R.OK(integer);
    }
    //根据传递进来的id进行删除指定数据
    @DeleteMapping("/unit/delUnit/{measureId}")
    public R delUnit(@PathVariable("measureId")Integer measureId){
        Integer integer = unitMeasureService.delUnit(measureId);
        return R.OK(integer);
    }
    //根据传递进来的id数组批量删除
    @DeleteMapping("/unit/delUnitArray")
    public R delUnitArray(@RequestBody List<Integer> arrayMeasureId){
        Integer integer = unitMeasureService.delUnitArray(arrayMeasureId);
        return R.OK(integer);
    }
}
